package com.subway.babynote;
/*水*/
import com.subway.babynote.syncservice.syncapi;
import com.subway.babynote.syncdata.errMessage;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;

public class login extends Activity implements OnClickListener {
	private Button log_button;
	EditText username_et;
	EditText password_et;
	//EditText passwordconfirm_et;
	Intent In;
	boolean isRemembered;
	private LinearLayout linearLayout, statistics, sync, more;
    TextView register_view;
    TextView hint_view;
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.login);
		In = new Intent();
		//initTabFunction();
		username_et = (EditText) findViewById(R.id.username_edit);
		password_et = (EditText) findViewById(R.id.passwd_edit);
		hint_view= (TextView)findViewById(R.id.hint_view);
		log_button = (Button) findViewById(R.id.log_button);

	//	CheckBox checkBox = (CheckBox) findViewById(R.id.remember_checkbox);
		register_view =(TextView)findViewById(R.id.register_view);

		log_button.setOnClickListener(this);
		register_view.setOnClickListener(this); 
	}
	
	

	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		if (v.equals(log_button)) {	
			String username=username_et.getText().toString();;
			String passwd=password_et.getText().toString();
			hint_view.setText(getResources().getString(R.string.logining));
			int ret=syncapi.getSyncImpl().LoginUser(username, passwd);
			if (ret==errMessage.err_nouser.errcode||ret==errMessage.err_passwd.errcode)
			{
				hint_view.setText(getResources().getString(R.string.loginfailure));
				return;
			}else{
		    
				hint_view.setText(getResources().getString(R.string.loginsuccess));
				In.setClass(login.this, maintab.class);
				startActivity(In);
			}
		}else if(v.equals(register_view)){
			In.setClass(login.this, register.class);
			startActivity(In);
			
		}
	}

	
	
	
}